﻿using Microsoft.Extensions.DependencyInjection;
using MyWpfFramework.Models;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace MyWpfFramework.Helper
{
    public class SqlsugarHelper
    {

        public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
        {
            ConnectionString = "datasource=D:\\MyGit\\my-wpf-framework\\MyWpfFramework\\bin\\Debug\\net6.0-windows\\MyFrame.db",//连接符字串
            DbType = SqlSugar.DbType.Sqlite,//数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        },
        db => {
            db.Aop.OnLogExecuted = (sql, pars) =>
            {
                Debug.WriteLine(UtilMethods.GetNativeSql(sql, pars));
            };
        });
       
       

    }

    public interface ILogger
    {
        void Log(string message);
    }
    public class Logger : ILogger
    {

        public void Log(string message)
        { 
            Console.WriteLine(message);
        }
    }
    public interface IDBoperation
    {
        void Connection();
    }
    public class DbOperation:IDBoperation
    {
        public void Connection()
        {
            Debug.WriteLine("连接完成");
        }
    }
    public class UseDI
    {
        IDBoperation? dbo;
        public void Connection()
        {
            dbo = App.Current.Services.GetService<IDBoperation>();
            dbo?.Connection();
        }

    }
}
